Skip to content

Conversation

@dzbarsky
Copy link
Contributor

However, it's not enough for tool_map to be on cc_toolchain_config - it must be on the toolchain itself to properly share the same exec platform as the action requesting the toolchain. Therefore we rearrange the implementation of the cc_toolchain macro to pass it to the rule, and teach the rule to accept it from either the attribute or the cc_toolchain_config. Eventually, cc_toolchain_config can be retired, though it will be a long journey.

@dzbarsky dzbarsky force-pushed the zbarsky/tool_map branch 4 times, most recently from 0ac92cf to ad72f0e Compare January 10, 2026 01:45
Copy link
Collaborator

@armandomontanez armandomontanez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together! I'll try to take a closer look early next week. If I don't get back to you in a timely manner, please ping me with a comment here.

@dzbarsky dzbarsky force-pushed the zbarsky/tool_map branch 3 times, most recently from 21a6ab9 to 79f0585 Compare January 12, 2026 07:57
@dzbarsky
Copy link
Contributor Author

Thanks for putting this together! I'll try to take a closer look early next week. If I don't get back to you in a timely manner, please ping me with a comment here.

@armandomontanez PTAL :)

Copy link
Collaborator

@armandomontanez armandomontanez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more small things, but overall looks great!

The macOS build is failing because macOS is currently doing a cross-compile to Linux and the tools are now exec-configured. This means llvm-libtool-darwin is getting selected as the archiver, but we end up using ar-style flags. Easy fix is to just merge the two tool maps to always use llvm-ar instead of llvm-libtool-darwin:

# This `select` happens under the target configuration. For macOS,
# llvm-libtool-darwin should be used when creating static libraries even if the
# exec platform is linux.
alias(
name = "all_tools",
actual = select({
"@platforms//os:macos": ":macos_tools",
"//conditions:default": ":default_tools",
}),
tags = ["manual"],
visibility = ["//visibility:public"],
)
COMMON_TOOLS = {
"@rules_cc//cc/toolchains/actions:assembly_actions": ":clang",
"@rules_cc//cc/toolchains/actions:c_compile": ":clang",
"@rules_cc//cc/toolchains/actions:cpp_compile_actions": ":clang++",
"@rules_cc//cc/toolchains/actions:link_actions": ":lld",
"@rules_cc//cc/toolchains/actions:objcopy_embed_data": ":llvm-objcopy",
"@rules_cc//cc/toolchains/actions:strip": ":llvm-strip",
}
cc_tool_map(
name = "default_tools",
tags = ["manual"],
tools = COMMON_TOOLS | {
"@rules_cc//cc/toolchains/actions:ar_actions": ":llvm-ar",
},
visibility = ["//visibility:private"],
)
cc_tool_map(
name = "macos_tools",
tags = ["manual"],
tools = COMMON_TOOLS | {
"@rules_cc//cc/toolchains/actions:ar_actions": ":llvm-libtool-darwin",
},
visibility = ["//visibility:private"],
)

A number of projects prefer ar style archivers for cross-language interop reasons anyways.

known_features = known_features,
enabled_features = enabled_features,
compiler = compiler,
cpu = select({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move these to a shared constant rather than copying. These CPU values are arcane, so minimizing duplication is important.

@@ -0,0 +1,46 @@
# Copyright 2018 The Bazel Authors. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright year needs to be current year for new files.

} | CC_TOOLCHAIN_CONFIG_PUBLIC_ATTRS | {
# Override tool_map to make it optional.
"tool_map": attr.label(
cfg = "exec",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this is handled properly, we need to remove the exec transition in the cc_tool_map:

cfg = "exec",

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm might want to pick with a condition matching whether or not this is enabled (_bazel_version_ge("9.0.0-pre.20250911"))

To prevent duplication, it might be best to abstract that check with something like bazel_supports_starlarkified_cc_toolchians()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants